package cc.rengu.igas.route.core.realize.credit.impl.upac;


import cc.rengu.igas.channel.upac.facade.base.Header;
import cc.rengu.igas.channel.upac.facade.bean.CustomerInfo;
import cc.rengu.igas.channel.upac.facade.request.CreditTransStateQueryRequest;
import cc.rengu.igas.channel.upac.facade.request.RepayRequest;
import cc.rengu.igas.channel.upac.facade.response.CreditTransStateQueryRespone;
import cc.rengu.igas.channel.upac.facade.result.Result;
import cc.rengu.igas.route.common.enums.SmartRouteRspEnums;
import cc.rengu.igas.route.core.realize.credit.DstChannelCreditService;
import cc.rengu.igas.route.facade.bean.PayeeInfo;
import cc.rengu.igas.route.facade.bean.PayerInfo;
import cc.rengu.igas.route.facade.request.IntelligenceCreditRequest;
import cc.rengu.igas.route.facade.request.IntelligenceResultQueryRequest;
import cc.rengu.igas.route.facade.response.IntelligenceCreditResponse;
import cc.rengu.igas.route.facade.response.IntelligenceResultQueryResponse;
import cc.rengu.igas.share.common.constant.ShareParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.dao.DstChannelCfgMapper;
import cc.rengu.oltp.service.common.dao.impl.DstChannelCfgMapperImpl;
import cc.rengu.oltp.service.common.entity.DstChannelCfg;
import cc.rengu.oltp.service.common.entity.PayOrderInfo;
import cc.rengu.oltp.service.common.entity.SysParam;
import cc.rengu.oltp.service.common.enums.BizStatusEnum;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.common.enums.PayTypeEnum;
import cc.rengu.oltp.service.common.enums.TransStatusEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.SysParamService;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;
import cc.rengu.oltp.service.realize.impl.SysParamServiceImpl;
import cc.rengu.oltp.utility.util.*;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;
import com.alibaba.fastjson.JSONObject;

/**
 * TODO 银联全渠道代付
 *
 * @author xionglz
 * @version 1.0
 * @date 2020-04-28
 */
public class UpacCreditServiceImpl implements DstChannelCreditService {
    /**
     * 默认渠道类型 07-互联网
     */
    private final static String DEFAULT_CHANNEL_TYPE = "07";
    /**
     * 默认资金来源 00-一般性付款
     */
    private final static String DEFAULT_SOURCE_OF_FUNDS = "00";
    /**
     * 银联全渠道代付交易码
     */
    private final static String UPAC_CREDIT_TXNNUM = "1200000000";
    /**
     * 通道类型为代付PT01 PT?? 商户选择其开通的产品时取自支付通道信息表T_P_DST_CHANNEL_CFG
     */
    private final static String DST_CHANNEL_TYPE = "PT01";
    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());

    @Override
    public IntelligenceCreditResponse credit(IntelligenceCreditRequest intelligenceCreditRequest) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        //设置公共应答信息
        IntelligenceCreditResponse intelligenceCreditResponse = new IntelligenceCreditResponse();
        intelligenceCreditResponse.setHeader(intelligenceCreditRequest.getHeader());
        intelligenceCreditResponse.setDstChannelTxnNum(UPAC_CREDIT_TXNNUM);
        intelligenceCreditResponse.setDstChannelId("UPAC");
        //创建dubbo请求对象，调用核心接口进行预扣款处理，赋值
        RepayRequest repayRequest = new RepayRequest();
        // 渠道类型 默认-07互联网接入
        repayRequest.setChannelType(DEFAULT_CHANNEL_TYPE);
        repayRequest.setProdType(DST_CHANNEL_TYPE);

        String esbSequenceNumber = null;
        String esbGlobalTraceNum = null;
        String esbGlobalPathNum = null;
        String mchntNo = null;
        String sysSeqNum = null;
        if (!StringUtil.isEmptyOrNull(intelligenceCreditRequest.getAdditionInfo())) {
            JSONObject jsonObject = JSONObject.parseObject(intelligenceCreditRequest.getAdditionInfo());
            if (null == jsonObject) {
                rglog.error("附加信息中存在esb流水相关信息必须存在");
                throw new BizException(SmartRouteRspEnums.TRANS_FAIL.getRespCode(), SmartRouteRspEnums.TRANS_FAIL.getRespDesc());
            }
            esbSequenceNumber = jsonObject.getString(ShareParamConstant.ESB_SEQUENCE_NUMBER);
            esbGlobalTraceNum = jsonObject.getString("globalTraceNum");
            esbGlobalPathNum = jsonObject.getString("globalPathNum");
            sysSeqNum = (String) jsonObject.get(TreeNodeConstant.SYS_SEQ_NUM);
            if (StringUtil.isEmptyOrNull(esbSequenceNumber) || StringUtil.isEmptyOrNull(esbGlobalTraceNum) ||
                    StringUtil.isEmptyOrNull(esbGlobalPathNum) || StringUtil.isEmptyOrNull(sysSeqNum)) {
                rglog.error("附加信息中存在esb流水相关信息必须存在");
                throw new BizException(SmartRouteRspEnums.TRANS_FAIL.getRespCode(), SmartRouteRspEnums.TRANS_FAIL.getRespDesc());
            }
            mchntNo = jsonObject.getString("upacMchntNo");
            if (!StringUtil.isEmptyOrNull(mchntNo)) {
                repayRequest.setUpacMchntNo(mchntNo);
                SysParamService sysParamService = new SysParamServiceImpl();
                SysParam sysParam = sysParamService.getSysParamInfo(intelligenceCreditRequest.getHeader().getInstId(), "ROUTE:UPAC:MCHNT2PROD:PT", mchntNo);
                if (null != sysParam && !StringUtil.isEmptyOrNull(sysParam.getParamValue())) {
                    repayRequest.setProdType(sysParam.getParamValue());
                    intelligenceCreditResponse.setAdditionInfo("{\"dstChannelType\":\"" + sysParam.getParamValue() + "\"}");
                } else {
                    rglog.error("该商户<{}>未配置其产品映射关系", mchntNo);
                    throw new BizException(SmartRouteRspEnums.CONFIG_ERROR.getRespCode(), SmartRouteRspEnums.CONFIG_ERROR.getRespDesc());
                }
            }
        }
        //账户类型
        repayRequest.setAcctType(intelligenceCreditRequest.getPayeeInfo().getAcctType());
        //银行账号
        repayRequest.setPayAcctNo(intelligenceCreditRequest.getPayeeInfo().getAcctNo());
        //代付客户信息有则上送 证件类型 (已确认可不上送)
        CustomerInfo customerInfo = new CustomerInfo();
        customerInfo.setCustName(intelligenceCreditRequest.getPayeeInfo().getAcctName());
        repayRequest.setCustomerInfo(customerInfo);
        //订单信息 金额及币种
        repayRequest.setOrderAmt(intelligenceCreditRequest.getTxnAmt());
        repayRequest.setOrderCcy(intelligenceCreditRequest.getTxnCrcyCode());
        //使用系统流水号
        repayRequest.setOrderId(sysSeqNum);
        repayRequest.setOrderTime(intelligenceCreditRequest.getHeader().getTransDate() + intelligenceCreditRequest.getHeader().getTransTime());
        //根据业务类型转换得到资金来源，未配置的转换则默认填写00一般性付款
        repayRequest.setSourcesOfFunds(DEFAULT_SOURCE_OF_FUNDS);
        //设置请求头
        Header header = new Header();
        BeanUtil.beanCopy(intelligenceCreditRequest.getHeader(), header);
        header.setTransDate(DateUtil.getCurrentDate());
        header.setTransTime(DateUtil.getCurrentTime());
        header.setTxnNum(UPAC_CREDIT_TXNNUM);
        repayRequest.setHeader(header);
        if (null != intelligenceCreditRequest.getPayerInfo()) {
            cc.rengu.igas.channel.upac.facade.bean.PayerInfo upacPayerInfo = new cc.rengu.igas.channel.upac.facade.bean.PayerInfo();
            if (!StringUtil.isEmptyOrNull(intelligenceCreditRequest.getPayerInfo().getAcctNo())) {
                upacPayerInfo.setPayerAccNo(intelligenceCreditRequest.getPayerInfo().getAcctNo());
                upacPayerInfo.setPayerAccNum(intelligenceCreditRequest.getPayerInfo().getAcctNo());
            }
            if (!StringUtil.isEmptyOrNull(intelligenceCreditRequest.getPayerInfo().getAcctType())) {
                upacPayerInfo.setPayerAccType(intelligenceCreditRequest.getPayerInfo().getAcctType());
            }
            if (!StringUtil.isEmptyOrNull(intelligenceCreditRequest.getPayerInfo().getAcctName())) {
                upacPayerInfo.setPayerName(intelligenceCreditRequest.getPayerInfo().getAcctName());
            }
            repayRequest.setPayerInfo(upacPayerInfo);
        }

        /* 初始化赋值 */
        //TODO  删除调用ESB模块，后续由项目组实现该模块调用

        return intelligenceCreditResponse;
    }


    private String calcTransferClearFee(String txnAmt) {
        String channelFee = "0.00";

        int lessOne = AmountUtil.compare("100000", AmountUtil.changeY2F(txnAmt));
        if (lessOne == 1) {
            rglog.trace("txnAmt = <{}>分，与100000分比较，较小", AmountUtil.changeY2F(txnAmt));
            return "0.05";
        }

        int moreFive = AmountUtil.compare(AmountUtil.changeY2F(txnAmt), "5000000");
        if (moreFive == 1) {
            rglog.trace("txnAmt = <{}>分，与5000000分比较，较大", AmountUtil.changeY2F(txnAmt));
            return "3.5";
        }

        rglog.trace("txnAmt = <{}>分，大于100000，小于5000000分", AmountUtil.changeY2F(txnAmt));
        channelFee = AmountUtil.multiplication(txnAmt, "0.00005", 2);

        return channelFee;
    }

    @Override
    public IntelligenceResultQueryResponse query(IntelligenceResultQueryRequest resultQueryRequest) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        PayOrderInfo origPayOrderInfo = (PayOrderInfo) xmlTreeUtil.getXmlTreeObjectValue("ORIG_PAY_ORDER_INFO", PayOrderInfo.class);
        IntelligenceResultQueryResponse intelligenceResultQueryResponse = new IntelligenceResultQueryResponse();
        intelligenceResultQueryResponse.setHeader(resultQueryRequest.getHeader());
        intelligenceResultQueryResponse.setDstChannelId("UPAC");
        CreditTransStateQueryRequest creditTransStateQueryRequest = new CreditTransStateQueryRequest();
        creditTransStateQueryRequest.setChannelType(DEFAULT_CHANNEL_TYPE);

        creditTransStateQueryRequest.setOrderTime(resultQueryRequest.getOrigTxnDate() + resultQueryRequest.getOrigTxnTime());
        creditTransStateQueryRequest.setProdType(DST_CHANNEL_TYPE);
        String esbSequenceNumber = null;
        String esbGlobalTraceNum = null;
        String esbGlobalPathNum = null;
        String mchntNo = null;
        String sysSeqNum = null;
        //查询原交易流水号，查询数据库成功继续，查询数据库失败则查询交易失败，查询数据库无数据则查询交易成功原交易失败
        if (!cc.rengu.oltp.utility.util.StringUtil.isEmptyOrNull(resultQueryRequest.getAdditionInfo())) {
            JSONObject jsonObject = JSONObject.parseObject(resultQueryRequest.getAdditionInfo());
            if (null == jsonObject) {
                rglog.error("附加信息中存在esb流水相关信息必须存在");
                throw new BizException(SmartRouteRspEnums.TRANS_FAIL.getRespCode(), SmartRouteRspEnums.TRANS_FAIL.getRespDesc());
            }
            esbSequenceNumber = jsonObject.getString(ShareParamConstant.ESB_SEQUENCE_NUMBER);
            esbGlobalTraceNum = jsonObject.getString("globalTraceNum");
            esbGlobalPathNum = jsonObject.getString("globalPathNum");
            sysSeqNum = (String) jsonObject.get(TreeNodeConstant.SYS_SEQ_NUM);
            if (StringUtil.isEmptyOrNull(esbSequenceNumber) || StringUtil.isEmptyOrNull(esbGlobalTraceNum) ||
                    StringUtil.isEmptyOrNull(esbGlobalPathNum) || StringUtil.isEmptyOrNull(sysSeqNum)) {
                rglog.error("附加信息中存在esb流水相关信息必须存在");
                throw new BizException(SmartRouteRspEnums.TRANS_FAIL.getRespCode(), SmartRouteRspEnums.TRANS_FAIL.getRespDesc());
            }
            creditTransStateQueryRequest.setOrderId(sysSeqNum);
            mchntNo = jsonObject.getString("upacMchntNo");
            if (!cc.rengu.oltp.utility.util.StringUtil.isEmptyOrNull(mchntNo)) {
                creditTransStateQueryRequest.setUpacMchntNo(mchntNo);
                SysParamService sysParamService = new SysParamServiceImpl();
                SysParam sysParam = sysParamService.getSysParamInfo(resultQueryRequest.getHeader().getInstId(), "ROUTE:UPAC:MCHNT2PROD:PT", mchntNo);
                if (null != sysParam && !cc.rengu.oltp.utility.util.StringUtil.isEmptyOrNull(sysParam.getParamValue())) {
                    creditTransStateQueryRequest.setProdType(sysParam.getParamValue());
                } else {
                    rglog.error("该商户<{}>未配置其产品映射关系", mchntNo);
                    throw new BizException(SmartRouteRspEnums.CONFIG_ERROR.getRespCode(), SmartRouteRspEnums.CONFIG_ERROR.getRespDesc());
                }
            }
        } else {
            rglog.error("附加信息中存在esb流水相关信息必须存在");
            throw new BizException(SmartRouteRspEnums.TRANS_FAIL.getRespCode(), SmartRouteRspEnums.TRANS_FAIL.getRespDesc());
        }
        Header header = new Header();
        BeanUtil.beanCopy(resultQueryRequest.getHeader(), header);
        header.setTxnNum("0000000401");
        creditTransStateQueryRequest.setHeader(header);


        DubboService dubboService = new DubboServiceImpl();
        Result<CreditTransStateQueryRespone> responseResult = (Result<CreditTransStateQueryRespone>) dubboService.callDubboInnerMethod(cc.rengu.igas.channel.upac.biz.impl.UpacCreditServiceImpl.class, "creditTransStateQuery", creditTransStateQueryRequest);
        //调用失败结果为空
        if (null == responseResult || null == responseResult.getResult() || !responseResult.isSuccess()) {
            intelligenceResultQueryResponse.setRespCode(SmartRouteRspEnums.TRANS_FAIL.getRespCode());
            intelligenceResultQueryResponse.setRespDesc(SmartRouteRspEnums.TRANS_FAIL.getRespDesc());
            return intelligenceResultQueryResponse;
        }
        BeanUtil.beanCopy(responseResult.getResult(), intelligenceResultQueryResponse);
        intelligenceResultQueryResponse.setOrigRetCode(responseResult.getResult().getOrigRespCode());
        intelligenceResultQueryResponse.setOrigRetMsg(responseResult.getResult().getOrigRespDesc());
        PayeeInfo payeeInfo = new PayeeInfo();
        payeeInfo.setAcctName(responseResult.getResult().getPayCardName());
        payeeInfo.setAcctNo(responseResult.getResult().getPayAcctNo());
        intelligenceResultQueryResponse.setPayeeInfo(payeeInfo);
        intelligenceResultQueryResponse.setTxnAmt(responseResult.getResult().getSettleAmt());
        intelligenceResultQueryResponse.setTxnCrcyCode(responseResult.getResult().getSettleCcy());
        intelligenceResultQueryResponse.setSettleDate(responseResult.getResult().getSettleDate());
        intelligenceResultQueryResponse.setDstChannelSsn(responseResult.getResult().getTraceNo());
        String respCode = responseResult.getResult().getRespCode();
        //查询交易无结果，设置查询失败
        if (StringUtil.isEmptyOrNull(respCode) || StringUtil.isEmptyOrNull(responseResult.getResult().getOrigRespCode())) {
            intelligenceResultQueryResponse.setRespCode(SmartRouteRspEnums.TRANS_FAIL.getRespCode());
            intelligenceResultQueryResponse.setRespDesc(SmartRouteRspEnums.TRANS_FAIL.getRespDesc());
            return intelligenceResultQueryResponse;
        }
        //查询交易有结果
        else {
            //查询交易成功
            if (OltpRpcdEnum.TRANS_SUCCESS.getRespCode().equalsIgnoreCase(respCode)) {
                String origRespCode = responseResult.getResult().getOrigRespCode();
                String origRespDesc = responseResult.getResult().getOrigRespDesc();
                //原交易状态为成功
                if (OltpRpcdEnum.TRANS_SUCCESS.getRespCode().equalsIgnoreCase(origRespCode)) {
                    intelligenceResultQueryResponse.setStatus("0");
                    intelligenceResultQueryResponse.setOrigRetCode(SmartRouteRspEnums.TRANS_SUCCESS.getRespCode());
                    intelligenceResultQueryResponse.setOrigRetMsg(SmartRouteRspEnums.TRANS_SUCCESS.getRespDesc());
                    //初始化商户真实扣款
                    //TODO  删除调用ESB模块，后续由项目组实现该模块调用

                }
                //查询成功，原交易未知(通道直接设置的查询交易应答码）
            } else if (OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode().equalsIgnoreCase(respCode)) {
                intelligenceResultQueryResponse.setRespCode(SmartRouteRspEnums.TRANS_SUCCESS.getRespCode());
                intelligenceResultQueryResponse.setRespDesc(SmartRouteRspEnums.TRANS_SUCCESS.getRespDesc());
                intelligenceResultQueryResponse.setStatus("2");
                intelligenceResultQueryResponse.setOrigRetCode(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode());
                intelligenceResultQueryResponse.setOrigRetMsg(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespDesc());
            }
            //查询交易失败
            else {
                intelligenceResultQueryResponse.setRespCode(SmartRouteRspEnums.TRANS_FAIL.getRespCode());
                intelligenceResultQueryResponse.setRespDesc(SmartRouteRspEnums.TRANS_FAIL.getRespDesc() + "[" + respCode + "]:" + responseResult.getResult().getRespDesc());
            }
        }
        return intelligenceResultQueryResponse;
    }

    @Override
    public String getReconKey(IntelligenceCreditRequest intelligenceCreditRequest) throws Exception {
        //全渠道直连银联对账key为 商户号+订单号+yyyyMMddHHmmss（订单时间）
        //若上送了银联商户号则使用银联商户号
        String sysSeqNum = null;
        if (!StringUtil.isEmptyOrNull(intelligenceCreditRequest.getAdditionInfo())) {
            String mchntNo = JSONObject.parseObject(intelligenceCreditRequest.getAdditionInfo()).getString("upacMchntNo");
            sysSeqNum = JSONObject.parseObject(intelligenceCreditRequest.getAdditionInfo()).getString(TreeNodeConstant.SYS_SEQ_NUM);
            if (!StringUtil.isEmptyOrNull(mchntNo) && !StringUtil.isEmptyOrNull(sysSeqNum)) {
                return mchntNo + sysSeqNum;
            }
        }
        //通过prodType查询银联商户号
        DstChannelCfgMapper dstChannelCfgMapper = new DstChannelCfgMapperImpl();
        DstChannelCfg dstChannelCfg = dstChannelCfgMapper.selectDstChannelCfgByPrimaryKey(
                intelligenceCreditRequest.getHeader().getInstId(), intelligenceCreditRequest.getDstChannelId(), DST_CHANNEL_TYPE);
        if (null == dstChannelCfg || StringUtil.isEmptyOrNull(dstChannelCfg.getProviderMchntNo())) {
            rglog.error("根据产品<{}>查询银联全渠道商户号出错", DST_CHANNEL_TYPE);
            throw new BizException(SmartRouteRspEnums.CONFIG_ERROR.getRespCode(), SmartRouteRspEnums.CONFIG_ERROR.getRespDesc());
        }
        return dstChannelCfg.getProviderMchntNo() + sysSeqNum;
    }

    /**
     * 初始化支付订单
     *
     * @param sysSeqNum        系统流水号
     * @param callIndex        调用顺序号
     * @param dstChannelTxnNum 通道交易码
     * @param dstChannelType   通道产品类型
     * @param reconKey         对账key
     * @param dateTime23       yyyyMMddHHmmSS 格式时间
     * @return 支付订单实体对象
     * @throws Exception 错误抛出异常
     */
    private PayOrderInfo initPayOrderInfo(Header esbHeader, String channelTxnNum, PayeeInfo payeeInfo, String mchntNo,
                                          String amt, String ccy, String postscript, PayerInfo payerInfo, String bizCode,
                                          String sysSeqNum, int callIndex, String dstChannelTxnNum, String dstChannelType,
                                          String reconKey, String dateTime23, String channelBizType) throws Exception {
        PayOrderInfo payOrderInfo = new PayOrderInfo();
        payOrderInfo.setBizStatus(BizStatusEnum.INIT.getStatus());
        payOrderInfo.setBizType(esbHeader.getBizType());
        payOrderInfo.setChannelDiscountAmt("0.00");
        payOrderInfo.setSysSeqNum(sysSeqNum);
//        payOrderInfo.setChannelFee();
//        payOrderInfo.setChannelOrderId();
        //针对不同的通道需要设置不同的对账key
        payOrderInfo.setChannelReconKey(reconKey);
//        payOrderInfo.setChannelSeqNum();
        payOrderInfo.setCreateTime(dateTime23);
//        payOrderInfo.setCustomerFee();
        payOrderInfo.setDstCallIndex("" + callIndex);
        payOrderInfo.setDstTxnNum(dstChannelTxnNum);
        payOrderInfo.setInstId(esbHeader.getInstId());
        payOrderInfo.setIssInstCode(payeeInfo.getOpenBankNo());
        payOrderInfo.setMchntNo(mchntNo);
        payOrderInfo.setMchntOrderId(sysSeqNum);
        payOrderInfo.setMsgDstId("ESB");
        //由DstChannelType存储实际的通道产品（UPAC则存储CT?? PT??）
        payOrderInfo.setDstChannelType(dstChannelType);
        payOrderInfo.setOrderAmt(amt);
        payOrderInfo.setOrderCcy(ccy);
        payOrderInfo.setOrderExpiryTime(DateUtil.getPrevioustimes(-60L, "yyyyMMddHHmmss"));
//        payOrderInfo.setOrigSysSeqNum();
//        payOrderInfo.setOrigTxnDate();
        payOrderInfo.setPayeeAcctInfo(payeeInfo.getAcctNo());
        payOrderInfo.setPayeeAcctType(payeeInfo.getAcctType());
        payOrderInfo.setPayeeRemark(postscript);
        payOrderInfo.setPayerAcctInfo(payerInfo.getAcctNo());
        payOrderInfo.setPayerAcctType(payerInfo.getAcctType());
//        payOrderInfo.setPayerRemark();
        payOrderInfo.setPayType(PayTypeEnum.OTHER_BANK_CARD.getPayType());
        payOrderInfo.setRealPayAmt(amt);
        payOrderInfo.setRemark1(bizCode);
//        payOrderInfo.setRemark2();
//        payOrderInfo.setRemark3();
//        payOrderInfo.setRespCode();
//        payOrderInfo.setRespDesc();
//        payOrderInfo.setRowno();
//        payOrderInfo.setSettleDate();
//        payOrderInfo.setTransBatchNo();
        payOrderInfo.setTransStatus(TransStatusEnum.TRANS_INIT.getStatus());
//        payOrderInfo.setTxnAuthCode();
        payOrderInfo.setTxnDate(esbHeader.getTransDate());
        payOrderInfo.setTxnNum(channelTxnNum);
        payOrderInfo.setTxnTime(esbHeader.getTransTime());
//        payOrderInfo.setUpdateTime();
        payOrderInfo.setUserId("ROUTE_VIRTUAL_TELLER");
        payOrderInfo.setChannelBizType(channelBizType);
        return payOrderInfo;
    }

    private PayOrderInfo updPayOrderInfo(PayOrderInfo payOrderInfo, TransStatusEnum transStatusEnum, String respCode, String respDesc, String settleDate, String channelSeqNum) throws Exception {
        if (TransStatusEnum.TRANS_SUCC.getStatus().equals(transStatusEnum.getStatus())) {
            payOrderInfo.setBizStatus(BizStatusEnum.FINISH.getStatus());
        } else if (TransStatusEnum.TRANS_TIMEOUT.getStatus().equals(transStatusEnum.getStatus())) {
            payOrderInfo.setBizStatus(BizStatusEnum.PROCESSING.getStatus());
        } else if (TransStatusEnum.SYSTEM_REJECT.getStatus().equals(transStatusEnum.getStatus())) {
            payOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
        } else {
            payOrderInfo.setBizStatus(BizStatusEnum.PROCESSING.getStatus());
        }
        payOrderInfo.setTransStatus(transStatusEnum.getStatus());
        payOrderInfo.setRespCode(respCode);
        payOrderInfo.setRespDesc(respDesc);
//        payOrderInfo.setRowno();
        payOrderInfo.setSettleDate(settleDate);
        if (!StringUtil.isEmptyOrNull(channelSeqNum)) {
            payOrderInfo.setChannelSeqNum(channelSeqNum);
        }
//        payOrderInfo.setTransBatchNo();
//        payOrderInfo.setTxnAuthCode();
        String dateTime23 = DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS");
        payOrderInfo.setUpdateTime(dateTime23);
        return payOrderInfo;
    }
}
